
cmake_minimum_required(VERSION 3.30)

message("\n======================================================================")
message("  --  示例项目喵")
message("======================================================================\n")

# 设置 C++ 特性，使用 C++11 喵
set(CMAKE_CXX_STANDARD 11) # 默认为空
set(CMAKE_CXX_STANDARD_REQUIRED True) # 默认为空

# 创建项目喵
project(HeadEnlargerSample VERSION 1.2.3.4)

# 使用 configure_package_config_file 和 write_basic_package_version_file 需 包含 CMakePackageConfigHelpers 喵
include(CMakePackageConfigHelpers)

# 安装目录常量喵：
# lib 目录在 linux 下为 /usr/local/lib 喵
# include 命令在 linux 下为 /usr/local/include 喵

# █████████████████████████████████████████████████████████████████████████████
# █████████████████████████████████████████████████████████████████████████████

# =============================================================================
# 静态库喵

# 添加一个静态库喵
add_library(s_lib STATIC third_party/static_lib/src/s_lib.cpp)
# 添加配置文件喵
configure_file("third_party/static_lib/config/lib_config.h.in" "s_lib/config.h")
# 添加包含目录喵
target_include_directories(s_lib PRIVATE third_party/static_lib/include "${PROJECT_BINARY_DIR}/s_lib")
target_include_directories(s_lib INTERFACE
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/third_party/static_lib/include> # 本库的包含目录喵
  $<INSTALL_INTERFACE:include/cmake/s_lib>) # 使用方的包含目录喵

# 生成包含导出内容的配置文件，供 find_package 使用喵
configure_package_config_file("third_party/static_lib/config/lib_config.cmake.in" # 母版文件喵
  "s_libConfig.cmake" # 生成的目标，名称格式特定喵
  INSTALL_DESTINATION "lib/cmake/s_lib" # 安装位置喵
  NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO)
# 为配置文件生成版本文件喵
write_basic_package_version_file("s_libConfigVersion.cmake" # 生成的目标，名称格式特定喵
  VERSION ${HeadEnlargerSample_VERSION} # 版本号喵
  COMPATIBILITY AnyNewerVersion) # 向后兼容喵

# 安装库喵
install(TARGETS s_lib # 库喵
  DESTINATION lib/cmake/s_lib # 安装位置喵
  EXPORT s_lib_ex) # 导出名称喵
# 安装头文件喵
install(FILES third_party/static_lib/include/s_lib.h # 头文件喵
  DESTINATION include/cmake/s_lib) # 安装位置喵

# 导出库喵
export(EXPORT s_lib_ex # 导出喵
  FILE s_lib_ex.cmake) # 导出文件喵
# 安装导出喵
install(EXPORT s_lib_ex # 导出喵
  FILE s_lib_ex.cmake # 导出文件喵
  DESTINATION lib/cmake/s_lib) # 安装位置喵

# 安装配置文件，供 find_package 使用喵
install(FILES
  "${CMAKE_CURRENT_BINARY_DIR}/s_libConfig.cmake"
  "${CMAKE_CURRENT_BINARY_DIR}/s_libConfigVersion.cmake"
  DESTINATION lib/cmake/s_lib) # 安装位置喵

# █████████████████████████████████████████████████████████████████████████████
# █████████████████████████████████████████████████████████████████████████████

# =============================================================================
# 动态库喵

# 添加一个动态库喵
add_library(d_dll SHARED third_party/shared_dll/src/d_dll.cpp)
# 添加配置文件喵
configure_file("third_party/shared_dll/config/dll_config.h.in" "d_dll/config.h")
# 添加包含目录喵
target_include_directories(d_dll PRIVATE third_party/shared_dll/include "${PROJECT_BINARY_DIR}/d_dll")
target_include_directories(d_dll INTERFACE
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/third_party/shared_dll/include> # 本库的包含目录喵
  $<INSTALL_INTERFACE:include/cmake/d_dll>) # 使用方的包含目录喵

# 生成包含导出内容的配置文件，供 find_package 使用喵
configure_package_config_file("third_party/shared_dll/config/dll_config.cmake.in" # 母版文件喵
  "d_dllConfig.cmake" # 生成的目标喵
  INSTALL_DESTINATION "lib/cmake/d_dll" # 安装位置喵
  NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO)
# 为配置文件生成版本文件喵
write_basic_package_version_file("d_dllConfigVersion.cmake" # 生成的目标喵
  VERSION ${HeadEnlargerSample_VERSION} # 版本号喵
  COMPATIBILITY AnyNewerVersion) # 向后兼容喵

# 安装库喵
install(TARGETS d_dll # 库喵
  DESTINATION lib/cmake/d_dll # 安装位置喵
  EXPORT d_dll_ex) # 导出名称喵
# 安装头文件喵
install(FILES third_party/shared_dll/include/d_dll.h # 头文件喵
  DESTINATION include/cmake/d_dll) # 安装位置喵

# 导出喵
export(EXPORT d_dll_ex # 导出喵
  FILE d_dll_ex.cmake) # 导出文件喵
# 安装导出喵
install(EXPORT d_dll_ex # 导出喵
  FILE d_dll_ex.cmake # 导出文件喵
  DESTINATION lib/cmake/d_dll) # 安装位置喵

# 安装配置文件，供 find_package 使用喵
install(FILES
  "${CMAKE_CURRENT_BINARY_DIR}/d_dllConfig.cmake"
  "${CMAKE_CURRENT_BINARY_DIR}/d_dllConfigVersion.cmake"
  DESTINATION lib/cmake/d_dll) # 安装位置喵

# █████████████████████████████████████████████████████████████████████████████
# █████████████████████████████████████████████████████████████████████████████

# =============================================================================
# 可执行文件喵

# 添加一个可执行文件喵
add_executable(main src/main.cpp)
# 添加配置文件喵
configure_file("config/sampleConfig.h.in" "hes_config.h")
# 添加包含目录喵
target_include_directories(main PUBLIC include "${PROJECT_BINARY_DIR}")
# 链接喵
target_link_libraries(main s_lib d_dll)

# =============================================================================
# 配置依赖关系喵

add_dependencies(main s_lib d_dll)
